package com.zmn.plat.services.impl.warranty.content;

import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.warranty.content.WarrantyContent;
import com.zmn.plat.model.entity.warranty.content.WarrantyContentQuery;
import com.zmn.plat.model.vo.warranty.WarrantyContentVO;
import com.zmn.plat.persistence.interfaces.warranty.content.WarrantyContentDao;
import com.zmn.plat.services.interfaces.warranty.content.WarrantyContentService;

@Service
public class WarrantyContentServiceImpl implements WarrantyContentService {

    @Resource
    WarrantyContentDao warrantyContentDao;

    @Override
    public WarrantyContent findByKey(Integer warrantyContentId) {
        return warrantyContentDao.findByKey(warrantyContentId);
    }

    @Override
    public List<WarrantyContent> findByKeys(List<Integer> warrantyContentIds) {
        if (CollectionUtils.isEmpty(warrantyContentIds)) {
            return Collections.emptyList();
        }
        return warrantyContentDao.findByKeys(warrantyContentIds);
    }

    @Override
    public List<WarrantyContent> listPageByQuery(WarrantyContentQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return warrantyContentDao.listPageByQuery(query);
    }

    @Override
    public List<WarrantyContentVO> listExportExcelPageByQuery(WarrantyContentQuery query) {
        return warrantyContentDao.listExportExcelPageByQuery(query);
    }

    @Override
    public List<WarrantyContent> listByQuery(WarrantyContentQuery query) {
        return warrantyContentDao.listByQuery(query);
    }

    @Override
    public List<WarrantyContent> listAll() {
        return warrantyContentDao.listAll();
    }

    @Override
    public Integer countByQuery(WarrantyContentQuery query) {
        return warrantyContentDao.countByQuery(query);
    }

    @Override
    public Integer updateStatusByKey(WarrantyContent warrantyContent) {
        return warrantyContentDao.updateStatusByKey(warrantyContent);
    }

    @Override
    public Integer updateStatusBatchByKey(List<Integer> ids, Integer status, String mcStaffName) {
        return warrantyContentDao.updateBatchStatusByKey(ids, status, mcStaffName);
    }

    @Override
    public Integer updateSortByKey(WarrantyContent warrantyContent) {
        return warrantyContentDao.updateSortByKey(warrantyContent);
    }

    @Override
    public Integer updateSortByKey(Integer warrantyContentId, Integer sort, String mcStaffName) {
        WarrantyContent warrantyContent = new WarrantyContent();
        warrantyContent.setWarrantyContentId(warrantyContentId);
        warrantyContent.setSort(sort);
        warrantyContent.setUpdater(mcStaffName);
        warrantyContent.setUpdateTime(DateUtil.getNow());

        return updateSortByKey(warrantyContent);
    }

    @Override
    public Integer updateByKey(WarrantyContent warrantyContent) {
        return warrantyContentDao.updateByKey(warrantyContent);
    }

    @Override
    public Integer insert(WarrantyContent warrantyContent) {
        return warrantyContentDao.insert(warrantyContent);
    }

    @Override
    public Integer deleteByKey(Integer warrantyContentId) {
        return warrantyContentDao.deleteByKey(warrantyContentId);
    }

}